$(document).ready(function(){
    if(localStorage.getItem("token") == null){
        alert("请先登录");
        window.location.href  = "/login";
    }
});

$("#user_logout").click(function () {
    //清除本地uid
    $.ajax({
        type: "GET",
        url: "/vei/logout",
        success: function (result) {
            localStorage.removeItem("token");
            window.location.href = "/login";
        }
    });
});
//修改密码
$("#modify_password").click(function () {
    $("#modify_password_modal").modal("show");
    $("#modify_password_button").click(function () {
        if($("#password").val() != $("#qrpassword").val()){
            alert("两次密码不一致!");
            $("#password").val("");
            $("#qrpassword").val("");
        }else{
            $.ajax({
                beforeSend: function (request) {
                    request.setRequestHeader("uid", localStorage.getItem("token"));
                },
                type:"POST",
                data:{password:$("#password").val()},
                url:"/user/update-pwd",
                success:function (data) {
                    alert(data.message);
                    window.location.reload();
                }
            });
        }
    });
});